package com.walter.epay.param.response;

import java.util.Objects;

/**
 *
 * @author wuchenxi
 * @date 2022-12-31 14:27:41
 */
public class EpayResponse<T> {

    /**
     * 状态码
     * <ul>
     *     <li>1：成功</li>
     *     <li>其他：失败</li>
     * </ul>
     */
    public Integer code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 响应数据
     */
    private T data;

    public boolean isSuccess() {
        return Objects.equals(code, 1);
    }

    public boolean checkOrderSuccess() {
        return Objects.equals(code, 1) || Objects.equals(code, -1)
                || Objects.equals(code, -2) || Objects.equals(code, -3);
    }

    public EpayResponse() {

    }

    public EpayResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public EpayResponse(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public static EpayResponse error(int code, String msg) {
        return new EpayResponse(code, msg);
    }

    public static <T> EpayResponse success(T data) {
        return new EpayResponse(1, data);
    }
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
